
class PCB:
    def __init__(self, name,  priority, arriveTime, needTime, workTime=0, state="W"):
        """
        :param name: PCB名称
        :param priority: 进程优先级
        :param arriveTime: 到达时间
        :param needTime: 需要运行时间
        :param workTime: 已经工作的时间
        :param state: 状态 就绪 W（ Wait）、运行 R（ Run）、或完成 F（ Finish）
        """
        self.name = name
        self.state = state
        self.priority = priority
        self.arriveTime = arriveTime
        self.needTime = needTime
        self.workTime = workTime

    def dorun(self, time):
        self.state = "R"
        self.needTime -= time
        self.workTime += time
        if self.needTime <= 0:
            self.state = "F"


    def wait(self):
        self.state = "W"
        if self.needTime<=0:
            self.state = "F"

    def __repr__(self):
        return "名称: {}, 优先级: {}, 到达时间: {}, 所需时间: {}, 工作时间: {}, 状态: {}".format(self.name, self.priority, self.arriveTime, self.needTime, self.workTime, self.state)



from PyQt5.QtWidgets import QLabel
from PyQt5.QtGui import QPalette
from PyQt5.QtCore import Qt, QRect

class PCBLabel(QLabel):
    def __init__(self, pcb, position):
        super().__init__()
        self.setText("名称:"+pcb.name+"\n优先级："+pcb.priority+"\n到达时间："+pcb.arriveTime+"\n所需时间："+pcb.needTime+"\n工作时间："+pcb.workTime+"\n状态："+pcb.state)
        # self.setObjectName("pcb")

        # 设置颜色
        self.setAutoFillBackground(True)
        self.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignTop)
        self.palette = QPalette()
        self.palette.setColor(QPalette.Window, Qt.green)
        self.setPalette(self.palette)

        # 设置位置
        self.setGeometry(QRect(position[0], position[1], 121, 161))

    def changeColor(self):
        self.palette.setColor(QPalette.Window, Qt.red)
        self.setPalette(self.palette)


